package com.backend.controller;


import com.backend.pojo.domain.New;
import com.backend.service.NewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/news")
@CrossOrigin//解决跨域问题，尽量加上，
//不加的话虽然数据能正常传输，但是前端页面会没有正常响应
public class NewController {
    @Autowired
    private NewService newService;

    // 1 查询所有(get请求)
    @GetMapping
    public List<New> New_selectAll() {
        return newService.selectAll();
    };

    // 2 根据newNo查询
    @GetMapping("/{newNo}")
    public New New_selectById(@PathVariable int newNo) {
        return newService.selectById(newNo);
    };

    // 3 多条件模糊查询
    @PostMapping("/selectByConditionMulti")
    public List<New> New_selectByConditionMulti(@RequestBody New news) {
        return newService.selectByConditionMulti(news);
    };

    // 4 多条件中选择一个条件查询
    @PostMapping("/selectByConditionSingle")
    public List<New> New_selectByConditionSingle(@RequestBody New news) {
        return newService.selectByConditionSingle(news);
    };

    // 5 增加
    @PostMapping("/addNew")
    public boolean New_addNew(@RequestBody New news) {
        return newService.addNew(news);
    };

    // 6 根据newNo修改
    @PutMapping
    public boolean New_update(@RequestBody New news) {
        return newService.update(news);
    };

    // 7 根据newNo删除一个
    @DeleteMapping("/{newNo}")
    public boolean New_deleteNewById(@PathVariable int newNo) {
        return newService.deleteNewById(newNo);
    };

    // 8 根据int[] newNos删除多个
    @DeleteMapping("/deleteManyNewByIds")
    public boolean New_deleteManyNewByIds(@RequestParam("newNos") int[] newNos) {
        return newService.deleteManyNewByIds(newNos);
    };
}

